﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using WMSADL.SY;
using WMSAML.SY;

namespace WMSABL.SY
{
    public class TGroupRoleRelation_BLL
    {
        TGroupRoleRelation_DAL dal = new TGroupRoleRelation_DAL();

        /// <summary>
        /// 保存数据
        /// </summary>
        public bool Update_TGroupRoleRelation(int gid, string str_rid)
        {
            if (dal.ExistsByGID(gid))
            {
                this.DeleteByGID(gid);
            }
            if (str_rid == "")
            {
                return true;
            }
            int result = 0;
            TGroupRoleRelation_Entity enity = new TGroupRoleRelation_Entity();
            enity.Group_id = gid;
            string[] arr = str_rid.Split(',');
            for (int i = 0; i < arr.Length - 1; i++)
            {
                enity.Role_id = Convert.ToInt32(arr[i]);
                if (Add(enity) >0) result++;
            }

            return result > 0 ? true : false;
        }
        /// <summary>
        /// 
        /// </summary>
        public int Add(TGroupRoleRelation_Entity entity)
        {
            return dal.Add(entity);
        }

        /// <summary>
        /// DeleteByGID
        /// </summary>
        public bool DeleteByGID(int gid)
        {
            return dal.DeleteByGID(gid);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(TGroupRoleRelation_Entity entity)
        {
            return dal.Update(entity);
        }

        /// <summary>
        /// ByID
        /// </summary>
        public bool ExistsByID(int id)
        {
            return dal.ExistsByID(id);
        }

        /// <summary>
        /// ByID
        /// </summary>
        /// <summary>
        public TGroupRoleRelation_Entity GetEntityByID(int id)
        {
            return dal.GetEntityByID(id);
        }
    }
}
